# -*- coding: utf-8 -*-

from django import template
from django.utils.translation import ugettext_lazy as _
from django.utils.safestring import mark_safe

from djdialogs.models import Dialog


register = template.Library()


@register.inclusion_tag('djdialogs/dialog.html', takes_context=True)
def dialog(context, identifier):
    lang = context.get('LANGUAGE_CODE', 'en-en')
    try:
        dialog = Dialog.objects.values().get(lang__istartswith=lang,
            ident=identifier)
        return dialog
    except InternalHelp.DoesNotExist:
        return {'title': _(u'Error'), 'text': _(u'<p>No dialog found for lang '
            u'%(lang)s and identifier %(id)s.</p>' % {'lang': lang,
                'id': identifier}), 'width': 500, 'opener_class': u'.opener',
                'id': 0}


@register.inclusion_tag('djdialogs/media.html')
def include_media(add_jquery=''):
    return {'jquery': add_jquery.lower() != 'no-jquery'}
